home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld: Complete Mac Interactive
/
Macworld Complete Mac Interactive CD)(1994).iso
/
The Best of BMUG
/
Utilities
/
Control Panels and Extensions
/
ClipboardMagician.76
/
testmagic.p
< prev
Wrap
Text File
|
1992-07-06
|
10KB
|
447 lines
program main;
uses
UConvertor;
const
infoType = 'CNV!';
convertMax = 20; { max number of convertor type supported }
type
PInteger = ^Integer;
HInteger = ^PInteger;
PLongint = ^Longint;
PResType = ^ResType;
EightChar = packed array[1..8] of char;
extraParm = record
theParmInfo: ParmInfo;
cnvtType: ResType;
cnvtHandle: Handle;
end;
var
myList: ListHandle;
aString: str255;
i: integer;
appleMenu, fileMenu, editMenu: menuHandle;
quit: boolean;
theWindow: windowPtr;
convertCount: integer;
convertor: array[1..convertMax] of ResType;
function GoExec (rInfoPtr: routineInfoPtr; pInfoPtr: parmInfoPtr; excAddr: Ptr): OSErr;
inline
$205F, $4e90;{ move.l (A7)+, A0; jsr (A0)}
procedure NumToHex (aLong: longint; var aEightChar: EightChar);
var
i, digit: integer;
begin
for i := 8 downto 3 do
begin
digit := BAnd(aLong, 15);
if digit < 10 then
aEightChar[i] := chr(ord('0') + digit)
else
aEightChar[i] := chr(ord('A') + digit - 10);
aLong := BSR(aLong, 4);
end;
aEightChar[1] := ' ';
aEightChar[2] := ' ';
end;
procedure GetSelected (var theType: ResType; var theHandle: Handle);
var
curCell: point;
tempBuf: packed array[1..12] of char;
v, i: integer;
theValue: longint;
dataLen: integer;
aChar: char;
begin
theValue := 0;
setPt(curCell, 0, 0);
if LGetSelect(TRUE, curCell, myList) then
begin
dataLen := 4;
LGetCell(@theType, dataLen, curCell, myList);
dataLen := 12;
LGetCell(@tempBuf, dataLen, curCell, myList);
for i := 1 to 6 do
begin
aChar := tempBuf[i + 6];
if aChar > '9' then
v := ord(aChar) - ord('A') + 10
else
v := ord(aChar) - ord('0');
theValue := theValue * 16 + v;
end;
end;
theHandle := Handle(theValue);
end;
procedure CopySelected;
var
ahandle: Handle;
aType: ResType;
dummy: integer;
begin
GetSelected(aType, aHandle);
if aHandle <> nil then
begin
dummy := ZeroScrap;
HLock(aHandle);
dummy := PutScrap(GetHandleSize(aHandle), aType, aHandle^);
HUnLock(aHandle);
end;
end;
procedure CutSelected;
var
curCell: point;
aHandle: Handle;
aType: ResType;
begin
setPt(curCell, 0, 0);
if LGetSelect(TRUE, curCell, myList) then
begin
GetSelected(aType, aHandle);
if aHandle <> nil then
begin
CopySelected;
DisposHandle(aHandle);
end;
LDelRow(1, curCell.v, myList);
end;
end;
procedure AddToList (theType: ResType; theHandle: Handle);
var
aEightChar: EightChar;
theCell: point;
theRow: integer;
begin
NumToHex(ord(theHandle), aEightChar);
theRow := LAddRow(1, myList^^.dataBounds.bottom, myList);
SetPt(theCell, 0, theRow);
LSetCell(@theType, 4, theCell, myList);
LAddToCell(@aEightChar, 8, theCell, myList);
end;
procedure PasteScrap;
var
disp: longint;
theSize: longint;
dummy: longint;
theType: ResType;
scrapPtr: PScrapStuff;
err: OSErr;
aHandle: Handle;
begin
scrapPtr := InfoScrap;
with scrapPtr^ do
begin
dummy := LoadScrap;
disp := 0;
while disp < scrapSize do
begin
theType := PResType(ord(scrapHandle^) + disp)^;
disp := disp + 4;
theSize := PLongint(ord(scrapHandle^) + disp)^;
disp := disp + 4;
HLock(scrapHandle);
if PtrToHand(Ptr(ord(scrapHandle^) + disp), aHandle, theSize) = NoErr then
AddToList(theType, aHandle);
HUnLock(scrapHandle);
disp := disp + theSize;
if odd(disp) then
disp := disp + 1;
end;
end;
end;
function CallByName (rtnRsrc: ResType; rtnName: str255; theParCount: integer; usingDefault: boolean; aParmPtr: parmInfoPtr): OSErr;
var
flag: SignedByte;
rtnInfo: routineInfo;
resHandle: handle;
aName: Str255;
rtnID, rtnIndex: integer;
i: integer;
tempHandle: Handle;
realID: Integer;
myExtraInfo: extraParm;
begin
resHandle := nil;
if rtnRsrc = InfoType then
begin
tempHandle := Get1NamedResource(rtnRsrc, rtnName);
if tempHandle <> nil then
begin
GetResInfo(tempHandle, realID, rtnRsrc, rtnName);
for i := 1 to convertCount do
begin
resHandle := Get1Resource(convertor[i], realID);
if resHandle <> nil then
begin
GetResInfo(resHandle, realID, rtnRsrc, rtnName);
leave;
end;
end;
end;
end
else
resHandle := Get1NamedResource(rtnRsrc, rtnName);
if resHandle <> nil then
begin
if rtnRsrc = 'CNVT' then
begin
aParmPtr^.dstHandle := nil;
with rtnInfo do
begin
entryPoint := @CallByName;
parmCount := theParCount;
useDefault := usingDefault;
end;
MoveHHi(resHandle);
flag := HGetState(resHandle);
HLock(resHandle);
CallByName := GoExec(@rtnInfo, aParmPtr, resHandle^);
HSetState(resHandle, flag);
end
else
begin
aName := ' Do????';
BlockMove(@rtnRsrc, @aName[7], 4);
with myExtraInfo do
begin
BlockMove(Ptr(aParmPtr), @myExtraInfo, SizeOf(parmInfo));
cnvtType := rtnRsrc;
cnvtHandle := resHandle;
end;
CallByName := CallByName('CNVT', aName, 3, usingDefault, @myExtraInfo);
BlockMove(@myExtraInfo, Ptr(aParmPtr), SizeOf(parmInfo));
end;
end
else
CallByName := ResError;
end;
procedure DoSelected;
var
aRoutineInfo: routineInfo;
aParmInfo: parmInfo;
aType: ResType;
aHandle: Handle;
aPtr: Ptr;
dataLen: longint;
dataEnd: longint;
begin
GetSelected(aType, aHandle);
if (testType = '****') or (testType = '____') or (testType = aType) then
if (aHandle <> nil) or (testType = '____') then
begin
with aRoutineInfo do
begin
entryPoint := @CallByName;
resID := testID;
parmCount := 4;
useDefault := true;
end;
with aParmInfo do
begin
srcType := aType;
srcHandle := aHandle;
dstHandle := nil;
end;
if xMain(@aRoutineInfo, @aParmInfo) = NoErr then
if aParmInfo.dstHandle <> nil then
with aParmInfo do
begin
if dstType <> 'scrp' then
AddToList(dstType, dstHandle)
else
begin
HLock(dstHandle);
aPtr := dstHandle^;
dataEnd := ord(aPtr) + GetHandleSize(dstHandle);
while ord(aPtr) < dataEnd do
begin
aType := PResType(aPtr)^;
aPtr := Ptr(ord(aPtr) + 4);
dataLen := PLongint(aPtr)^;
aPtr := Ptr(ord(aPtr) + 4);
if PtrToHand(aPtr, aHandle, dataLen) = NoErr then
AddToList(aType, aHandle);
if odd(dataLen) then
dataLen := dataLen + 1;
aPtr := Ptr(ord(aPtr) + dataLen);
end;
HUnLock(dstHandle);
DisposHandle(dstHandle);
end;
end;
end;
end;
procedure Initalize;
var
aString: str255;
r, bounds: rect;
cSize: point;
i, n, anID: integer;
aType: ResType;
aName, cnvStr: str255;
aHandle: Handle;
begin
convertCount := 1;
convertor[1] := 'CNVT';
n := CountResources('CNVT');
cnvStr := ' Do';
{ find out all convertor type supported by ' DoXXXX' CNVT }
for i := 1 to n do
begin
SetResLoad(false);
aHandle := GetIndResource('CNVT', i);
SetResLoad(true);
if aHandle <> nil then
begin
GetResInfo(aHandle, anID, aType, aName);
if (length(aName) = 10) & (IUMagIDString(@aName[1], @cnvStr[1], 6, 6) = 0) then
if convertCount < convertMax then
begin
convertCount := convertCount + 1;
BlockMove(@aName[7], @convertor[convertCount], 4);
end;
end;
end;
aString := ' ';
aString[1] := chr(appleMark);
appleMenu := NewMenu(1, aString);
AddResMenu(appleMenu, 'DRVR');
aString := 'File';
fileMenu := NewMenu(2, aString);
AppendMenu(fileMenu, 'Test/T;-;Quit/Q');
aString := 'Edit';
editMenu := NewMenu(3, aString);
AppendMenu(editMenu, 'Cut/X;Copy/C;Paste/V');
InsertMenu(appleMenu, 0);
InsertMenu(fileMenu, 0);
InsertMenu(editMenu, 0);
DrawMenuBar;
quit := false;
InitCursor;
SetRect(r, 20, 50, 140, 180);
theWindow := NewWindow(nil, r, '', true, 2, Pointer(-1), false, 0);
SetPort(theWindow);
OffsetRect(r, -20, -50);
InsetRect(r, 1, 1);
r.right := r.right - 15;
SetRect(bounds, 0, 0, 1, 0);
SetPt(cSize, r.right - r.left, 16);
myList := LNew(r, bounds, cSize, 0, theWindow, true, false, false, true);
with myList^^ do
begin
selFlags := lOnlyOne;
listFlags := lDoVAutoScroll;
end;
PasteScrap;
end;
procedure DoMenu (result: longint);
var
menu, item: integer;
begin
menu := HiWord(result);
item := LoWord(result);
case menu of
1:
begin
GetItem(appleMenu, item, aString);
i := OpenDeskAcc(aString);
end;
2:
begin
case item of
1:
DoSelected;
3:
quit := true;
end;
end;
3:
begin
case item of
1:
CutSelected;
2:
CopySelected;
3:
PasteScrap;
end
end;
end;
HiliteMenu(0);
end;
procedure MainEventLoop;
var
event: EventRecord;
aWindow: windowPtr;
locPt: point;
part: integer;
i: integer;
begin
SystemTask;
if GetNextEvent(everyEvent, event) then
;
case event.what of
activateEvt:
if WindowPtr(event.message) = theWindow then
begin
LActivate(odd(event.modifiers), myList);
end;
mouseDown:
begin
part := FindWindow(event.where, aWIndow);
case part of
inDesk:
;
inSysWindow:
SystemClick(event, aWindow);
inMenuBar:
begin
DoMenu(MenuSelect(event.where));
end;
inContent:
if FrontWindow <> theWindow then
SelectWindow(theWindow)
else
begin
locPt := event.where;
GlobalToLocal(locPt);
if LClick(locPt, event.modifiers, myList) then
DoSelected;
end;
end;
end;
keyDown:
if BitAnd(event.modifiers, CmdKey) <> 0 then
DoMenu(MenuKey(Chr(BitAnd(event.message, CharCodeMask))));
updateEvt:
begin
BeginUpdate(theWindow);
LUpdate(theWindow^.VisRgn, myList);
EndUpdate(theWindow);
end;
end;
end;
begin
Initalize;
repeat
MainEventLoop;
until quit;
LDispose(myList);
end.